//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _CMEDIASERVER_H_
#define _CMEDIASERVER_H_

class CMediaServer : public dbus::CObject<CMediaServer>
{
public:
    CMediaServer();
    ~CMediaServer();
    
private:
////////////////////////
// database functions
//
    void InitDatabase();
    void OpenDatabase();
    void PrepareQueries();

////////////////////////
// data functions
//
public:
    int CreateFolder(const std::string &pFolder);
    int GetFolderID(const std::string &pFolder,bool pCreate=false);
    void InsertItemData(int pItemID,const std::string &pKey,const std::string &pValue);
    void AddMediaItem(const io::CURI &pURI,const std::string &pMime,const std::map<std::string,std::string> &pData);

//dbus functions
public:
    template <class tIntrospector>
    static void Introspect(tIntrospector &pI)
    {
        pI.template AddMethod<void(const io::CURI&,const std::string&,const std::map<std::string,std::string>&)>("AddMediaItem",
                                                                                    &CMediaServer::AddMediaItem);
    }

//data
	CDatabase mDB;

	struct
	{
	    CDBQuery mInsertFolder;
	    CDBQuery mInsertItem;
	    CDBQuery mInsertItemData;
	    CDBQuery mGetFolderID;
	} mQueries;
};

#endif
